package com.example.blue.musicplay.adapter;

import android.content.Context;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.blue.musicplay.R;
import com.example.blue.musicplay.basic.Online_Gird_item_info;
import com.example.blue.musicplay.pool.ObjectPool;
import com.lidroid.xutils.BitmapUtils;

import java.util.List;

/**
 * Created by blue on 2016/9/22.
 */

public class Online_GridView_Adapter extends BaseAdapter {
    private static final String TAG = "Online_GridView_Adapter--->";
    private List<Online_Gird_item_info> item_list = null ;
    private Context context ;

    public Online_GridView_Adapter(Context context){
        this.context = context;
    }
    public Online_GridView_Adapter(Context context,List<Online_Gird_item_info> item_list) {
        this.context = context;
        this.item_list = item_list;
    }
    public void setItem_list (List<Online_Gird_item_info> item_list) {
        this.item_list = item_list;
    }
    @Override
    public int getCount() {
        return 6;
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

       if (convertView ==  null) {
           convertView = LayoutInflater.from(context).inflate(R.layout.main_online_layout_item, null);
       }
        item_list = (List<Online_Gird_item_info>) ObjectPool.getInstance().getObject("Item_List");
        if (item_list == null) {
            Log.d(TAG, "getView:  ------------------------");
            ImageView imageView = (ImageView) convertView.findViewById(R.id.ItemImage);
           imageView.setImageResource(R.drawable.pictures_no);
            TextView textView = (TextView) convertView.findViewById(R.id.grid_view_text);
            textView.setText("正在加载....");
        }else {
            ImageView imageView = (ImageView) convertView.findViewById(R.id.ItemImage);
            BitmapUtils utils = new BitmapUtils(context);
            utils.display(imageView, item_list.get(position).getImage_uri());
            Log.d(TAG, "getView: "+item_list.get(position).getImage_uri());
            TextView textView = (TextView) convertView.findViewById(R.id.grid_view_text);
            textView.setText(item_list.get(position).getSong_name());
        }
        return convertView;
    }
}
